#!/bin/bash

#This scripts is for centos 7 install php 7

#add the user for php-fpm

php_version=7.1.7

useradd -M -s /sbin/nologin www

#install deps of needed
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel wget gcc

#download php7

wget -c -O php-${php_version}.tar.gz http://hk1.php.net/get/php-${php_version}.tar.gz/from/this/mirror

#extra the tar package
tar zxf php-${php_version}.tar.gz

cd php-${php_version}

#Configure
./configure --prefix=/usr/local/php7 --exec-prefix=/usr/local/php7 --bindir=/usr/local/php7/bin --sbindir=/usr/local/php7/sbin --includedir=/usr/local/php7/include --libdir=/usr/local/php7/lib/php --mandir=/usr/local/php7/php/man --with-config-file-path=/usr/local/php7/etc --with-mysql-sock=/tmp/mysql.sock --with-mcrypt=/usr/include --with-mhash --with-openssl --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache --enable-fpm --enable-fastcgi --with-fpm-user=www --with-fpm-group=www --without-gdbm --disable-fileinfo

#Compile
make

#Install
make install

#php-fpm init control script
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

#php configure
cp php.ini-development /usr/local/php7/etc/php.ini

#execute privilege
chmod +x /etc/init.d/php-fpm

#configure php-fpm
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf

#configure the www to run php-fpm
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

#start php-fpm
/etc/init.d/php-fpm start
